-
Notifications
You must be signed in to change notification settings - Fork 15.5k
[libc] Add IN6_IS_ADDR_LOOPBACK
#172312
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
[libc] Add IN6_IS_ADDR_LOOPBACK
#172312
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Contributor
Author
This stack of pull requests is managed by Graphite. Learn more about stacking. |
Member
|
@llvm/pr-subscribers-libc Author: Connector Switch (c8ef) ChangesFull diff: https://github.com/llvm/llvm-project/pull/172312.diff 2 Files Affected:
diff --git a/libc/include/llvm-libc-macros/netinet-in-macros.h b/libc/include/llvm-libc-macros/netinet-in-macros.h
index f97a2dd0c3fda..3148aed6bb112 100644
--- a/libc/include/llvm-libc-macros/netinet-in-macros.h
+++ b/libc/include/llvm-libc-macros/netinet-in-macros.h
@@ -44,6 +44,15 @@
(__LLVM_LIBC_CAST(reinterpret_cast, uint32_t *, a)[2]) == 0 && \
(__LLVM_LIBC_CAST(reinterpret_cast, uint32_t *, a)[3]) == 0)
+#define IN6_IS_ADDR_LOOPBACK(a) \
+ ((__LLVM_LIBC_CAST(reinterpret_cast, uint32_t *, a)[0]) == 0 && \
+ (__LLVM_LIBC_CAST(reinterpret_cast, uint32_t *, a)[1]) == 0 && \
+ (__LLVM_LIBC_CAST(reinterpret_cast, uint32_t *, a)[2]) == 0 && \
+ (__LLVM_LIBC_CAST(reinterpret_cast, uint8_t *, a)[12]) == 0 && \
+ (__LLVM_LIBC_CAST(reinterpret_cast, uint8_t *, a)[13]) == 0 && \
+ (__LLVM_LIBC_CAST(reinterpret_cast, uint8_t *, a)[14]) == 0 && \
+ (__LLVM_LIBC_CAST(reinterpret_cast, uint8_t *, a)[15]) == 1)
+
#define IN6_IS_ADDR_LINKLOCAL(a) \
((__LLVM_LIBC_CAST(reinterpret_cast, uint8_t *, a)[0]) == 0xfe && \
(__LLVM_LIBC_CAST(reinterpret_cast, uint8_t *, a)[1] & 0xc0) == 0x80)
diff --git a/libc/test/include/netinet_in_test.cpp b/libc/test/include/netinet_in_test.cpp
index d70c780800858..15e57ccef7ac5 100644
--- a/libc/test/include/netinet_in_test.cpp
+++ b/libc/test/include/netinet_in_test.cpp
@@ -19,6 +19,11 @@ TEST(LlvmLibcNetinetInTest, IN6Macro) {
buff[i] = 0;
}
+ EXPECT_FALSE(IN6_IS_ADDR_LOOPBACK(buff));
+ buff[15] = 1;
+ EXPECT_TRUE(IN6_IS_ADDR_LOOPBACK(buff));
+ buff[15] = 0;
+
buff[0] = 0xfe;
buff[1] = 0x80;
EXPECT_TRUE(IN6_IS_ADDR_LINKLOCAL(buff));
|
This was referenced Dec 16, 2025
Contributor
Author
Merge activity
|
533e1f5 to
3a76cf5
Compare
Base automatically changed from
users/c8ef/12-15-_libc_add_in6_is_addr_unspecified_
to
main
December 18, 2025 15:06
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.

This patch adds the
IN6_IS_ADDR_LOOPBACKmacro, which checks whether an address is loopback address.